﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using ChatLib;
using System.Collections;

namespace Chat
{
    public partial class FormConnectScreencast : Form
    {
        FormScreencast frmScreencast;

        public FormConnectScreencast()
        {
            InitializeComponent();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnConnect_Click(object sender, EventArgs e)
        {
            Connect();
        }

        private void FormConnectScreencast_Load(object sender, EventArgs e)
        {
            try
            {
                listScreencasts.Items.Clear();
                ArrayList Screencasts = Global.server.GetScreencasts();

                foreach (object o in Screencasts)
                {
                    listScreencasts.Items.Add(o.ToString());
                }
            }
            catch { }
        }

        private void btnRefresh_Click(object sender, EventArgs e)
        {
            try
            {
                listScreencasts.Items.Clear();
                ArrayList Screencasts = Global.server.GetScreencasts();

                foreach (object o in Screencasts)
                {
                    listScreencasts.Items.Add(o.ToString());
                }
            }
            catch { }
        }

        private void listScreencasts_DoubleClick(object sender, EventArgs e)
        {
            Connect();
        }

        void Connect()
        {
            try
            {
                string Scr = listScreencasts.SelectedItem.ToString();
                string ipAdress = Scr.Remove(Scr.IndexOf(' '));

                frmScreencast = new FormScreencast(ipAdress);
                frmScreencast.Show();
                this.Hide();
            }
            catch
            {
                MessageBox.Show("Error");
            }
        }
    }
}
